package com.usian.controller;

import com.usian.config.FeignSupply;
import com.usian.config.ResponseResult;
import com.usian.pojo.Supply;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/supply")
public class SupplyController {
    @Autowired
    private FeignSupply feignSupply;
    @RequestMapping("/findAll")
    public List<Supply> findAll(@RequestBody Supply supply){
        return feignSupply.findAll(supply);
    }
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody Supply supply){
        try {
            feignSupply.insert(supply);
            return ResponseResult.errorResult(200,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(500,"添加失败12");
        }
    }
    @PostMapping("/update")
    public ResponseResult update(@RequestBody Supply supply){
        try {
            feignSupply.update(supply);
            return ResponseResult.errorResult(200,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(500,"修改失败");
        }
    }
    @PostMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Integer id){
        try {
            feignSupply.delete(id);
            return ResponseResult.errorResult(200,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.errorResult(9990,"删除失败");
        }
    }
    @GetMapping("/findAllByid")
    public Supply findAllByid(@RequestParam("id") Integer id){
return feignSupply.findAllByid(id);
    }
}
